package cn.softwin.controller.customer;


import cn.softwin.domain.PageBean;
import cn.softwin.pojo.CstCustomer;
import cn.softwin.service.impl.CustumerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/queryCustomerServlet")
public class QueryCustomerServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//客户端往服务端传输
        CstCustomer cstCustomer = new CstCustomer();
        String pageSize = request.getParameter("pageSize");
        // TODO Auto-generated method stub
        //1获取参数
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");
        if (currentPage==null||currentPage==""){
            currentPage = "1";
        }
        if (rows==null||rows==""){
            rows="15";
        }
        //2.调用service方法来查询
        CustumerServiceImpl custumerService = new CustumerServiceImpl();
        PageBean<CstCustomer> selectByPage = custumerService.selectByPage(Integer.valueOf(currentPage), Integer.valueOf(rows));
        //3.把selectByPage存入Request里
        request.setAttribute("pb", selectByPage);
        request.getRequestDispatcher("customer/list.jsp").forward(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

}
